//
//  UIColor+Extensions.swift
//  status
//
//  Created by 彳亍 on 2017/3/22.
//  Copyright © 2017年 彳亍. All rights reserved.
//

import UIKit

extension UIColor {
    
    /// HEX color
    ///
    /// - Parameters:
    ///   - hex: 16 进制编码
    ///   - alpha: 透明度
    /// - Returns: UIColor
    class func ch_colorWithHex(hex:UInt32, alpha:CGFloat = 1.0) -> UIColor {
        let red =  (hex & 0xFF0000) >> 16
        let green = (hex & 0x00FF00) >> 8
        let blue = (hex & 0x0000FF)
        return ch_color(red: red, green: green, blue: blue, alpha: alpha)
    }
    
    
    /// 随机色
    ///
    /// - Returns: UIColor
    class func ch_randomColor() -> UIColor {
        return ch_color(red: arc4random_uniform(256), green: arc4random_uniform(256), blue: arc4random_uniform(256))
    }
    
    /// RGB Color
    ///
    /// - Parameters:
    ///   - red:  红色
    ///   - green: 绿色
    ///   - blue: 蓝色
    ///   - alpha: 透明度
    /// - Returns: UIColor
    class func ch_color(red:UInt32, green:UInt32, blue:UInt32, alpha:CGFloat = 1.0) -> UIColor {
        return UIColor(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: alpha)
    }
    
}
